package activities.project3.group3.s12cs342;

import tools.Project3.Group3.s12cs342.AsyncCloudScoreUp;
import DataStructures.Project3.Group3.s12cs342.ScoreContainer;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class ShowScoresActivity extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
	
		super.onCreate(savedInstanceState);
		setContentView(R.layout.single_score);
		
		Quiz mApp = ((Quiz)getApplicationContext());
		int total = mApp.getTotalScore();
		int score = mApp.getCurrentScore();
		
		Button menu = (Button) findViewById(R.id.menuBtn);
		Button exit = (Button) findViewById(R.id.exitBtn);
		
		
		TextView scoreTV = (TextView) findViewById(R.id.scoreTV);

		SharedPreferences app_preferences = PreferenceManager
				.getDefaultSharedPreferences(this);
		String pass = app_preferences.getString("pass", "No Item");
		String name = app_preferences.getString("name", "No Item");
		
		
		scoreTV.setText("Your Score is " + score + " out of " + total);
		float a = score;
		float b = total;
		ScoreContainer temp = new ScoreContainer(mApp.getId(), ""+(Math.round(a/b *100)), pass);
		
		
		 new AsyncCloudScoreUp(name,  temp).execute();
		menu.setOnClickListener(new OnClickListener (){

			public void onClick(View arg0) {
				Intent i = new Intent(ShowScoresActivity.this, QuizMasterActivity.class);
				startActivity(i);
				
			}
			
		});
		exit.setOnClickListener(new OnClickListener (){

			public void onClick(View arg0) {
				Intent i = new Intent(ShowScoresActivity.this, AuthenticateActivity.class);
				startActivity(i);
				
			}
			
		});
				
	}
	
	
}
